package com.kfm.springboot.controller;

import com.github.pagehelper.PageInfo;
import com.kfm.springboot.domain.User;
import com.kfm.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@RestController
public class UserController {

    @Autowired
    private UserService service;

//    @RequestMapping(value = "/user", method = RequestMethod.GET)
    @GetMapping("/user")
    public ModelAndView hello(){
        // /templates/user/user.html
        ModelAndView mv = new ModelAndView("user/user");
        return mv;
    }

    @GetMapping("/user/list")
    public PageInfo<User> list(
            User user,
            @RequestParam(value = "page", defaultValue = "1") int pageNum
            , @RequestParam(value = "limit", defaultValue = "5")int pageSize){
        PageInfo<User> all = service.findAll(user, pageNum, pageSize);
        return all;
    }


    @DeleteMapping("/user/{id}")
    public String delete(@PathVariable("id") Integer id){
        int remove = service.remove(id);
        if (remove > 0){
            return "success";
        }
        return "fail";
    }



}
